package com.study.rabbitmq2.work;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.study.rabbitmq2.util.ConnectionUtil;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * @Author chenyeqing
 * @Date 2021/11/21 16:08
 */
public class Send {

    private final static String QUEUE_NAME = "test_work_queue";

    public static void main(String[] args) throws IOException, InterruptedException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();

        Channel channel = connection.createChannel();

        // 声明队列
        channel.queueDeclare(QUEUE_NAME, false, false, false, null);

        for (int i = 0; i < 50; i++) {
            String msg = "Hello Work" + i;
            channel.basicPublish("", QUEUE_NAME, null, msg.getBytes());
            System.out.println("[x] Send " + msg);

            Thread.sleep(i * 2);
        }

        channel.close();
        connection.close();
    }
}
